package com.yantong.mapper;

import com.yantong.pojo.CommisLogsParams;
import com.yantong.pojo.CommissionLog;
import com.yantong.pojo.CommissionLogExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author kanghaixin
 */
public interface CommissionLogMapper {
    /**
     * 条件统计
     * @param example
     * @return
     */
    int countByExample(CommissionLogExample example);

    /**
     * 条件删除
     * @param example
     * @return
     */
    int deleteByExample(CommissionLogExample example);

    /**
     * 主键删除
     * @param id
     * @return
     */
    int deleteByPrimaryKey(Long id);

    /**
     * 全字段插入
     * @param record
     * @return
     */
    int insert(CommissionLog record);

    /**
     * 适配插入
     * @param record
     * @return
     */
    int insertSelective(CommissionLog record);

    /**
     * 条件查询
     * @param example
     * @return
     */
    List<CommissionLog> selectByExample(CommissionLogExample example);
    List<CommissionLog> selectByExample(CommissionLogExample example, RowBounds rowBounds);

    /**
     * 主键查询  详情
     * @param id
     * @return
     */
    CommissionLog selectByPrimaryKey(Long id);

    /**
     * 条件适配更新
     * @param record
     * @param example
     * @return
     */
    int updateByExampleSelective(@Param("record") CommissionLog record, @Param("example") CommissionLogExample example);

    /**
     * 条件全量更新
     * @param record
     * @param example
     * @return
     */
    int updateByExample(@Param("record") CommissionLog record, @Param("example") CommissionLogExample example);

    /**
     * 将订单相关的id置为无效
     *
     * @param orderId 订单id
     * @param productId 商品id
     * @return int
     * @author liaozhaogui
     * @date 2020/9/26 22:24
     */
    int updateByOrderId(@Param("orderId") Long orderId, @Param("productId") Long productId);

    /**
     * 将订单相关的id置为无效
     *
     * @param orderId 订单id
     * @param productId 商品id
     * @return int
     * @author liaozhaogui
     * @date 2020/9/26 22:24
     */
    int updateCommissionByOrderId(@Param("orderId") Long orderId);

    /**
     * 主键适配更新
     * @param record
     * @return
     */
    int updateByPrimaryKeySelective(CommissionLog record);

    /**
     * 主键全量更新
     * @param record
     * @return
     */
    int updateByPrimaryKey(CommissionLog record);


    /**
     * 条件查询
     *
     * @param params
     * @param rowBounds
     * @return
     */
    List<CommissionLog> listByParams(CommisLogsParams params, RowBounds rowBounds);

    BigDecimal countCommissionLogs(CommisLogsParams params);

    /**
     * 条件查询 不分页
     *
     * @param params
     * @return
     */
    List<CommissionLog> listByParams(CommisLogsParams params);

    Double commissionTotal(@Param("mid") Long mid);

    /**
     * 条件统计
     * @param params
     * @return
     */
    int countByParams(CommisLogsParams params);

    /**
     * 获取累积佣金
     * @param mid
     * @param isGrant 0-未发放，1-已发放
     * @return
     */
    Double commissionCount(@Param("mid") Long mid, @Param("isGrant") Integer isGrant);

    /**
     * 获取门店  时间范围内已发放佣金总计
     * @param mid
     * @param start
     * @param end
     * @return
     */
    Double getMidGrantCommissionTotal(@Param("mid") Long mid, @Param("start") Date start, @Param("end") Date end);

    void insertSelectiveBatch(List<CommissionLog> commissionLogs);

   List<CommissionLog> selectByUserAgentCommission();

    int activeCommissionLog(Long orderId);
}